package com.aaa.dao.impl;

import com.aaa.dao.MovieDao;
import com.aaa.dao.MtypeDao;
import com.aaa.entity.Mtype;
import com.aaa.entity.Ptype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Repository
public class MtypeDaoImpl implements MtypeDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    private RowMapper<Mtype> rowMapper=new RowMapper<Mtype>() {
        public Mtype mapRow(ResultSet resultSet, int i) throws SQLException {
            Mtype mtype=new Mtype();
            mtype.setMid(resultSet.getLong("mid"));
            mtype.setMname(resultSet.getString("mname"));
            return mtype;
        }
    };

    public List<Mtype> listAll() {
        String sql="select mid,mname from mtype";
        List<Mtype> result = this.jdbcTemplate.query(sql, rowMapper);
        return result;
    }
}
